package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.IntervenesApi;
import com.als.healthymananger.entity.Intervene;
import com.als.healthymananger.service.IntervenesService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/intervence/plan")
public class IntervenesController implements IntervenesApi {
    @Autowired
    private IntervenesService intervenesService;

    @Override
    public RespBean createIntervene(Intervene intervene) {
        return intervenesService.save(intervene)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteIntervenes(int interveneId) {
        return intervenesService.removeById(interveneId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateIntervenes(int interveneId, Intervene intervene) {
        return intervenesService.updateById(intervene)? RespBean.ok("修改成功"): RespBean.badRequest("修改失败");
    }

    @Override
    public RespBean getIntervenes(int interveneId) {
        Intervene intervene = intervenesService.getById(interveneId);
        return intervene == null? RespBean.badRequest("获取失败"): RespBean.ok("获取成功", intervene);
    }
}
